<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <script src="layui/layui.js"></script>
</head>
<body>
<div style="width: 30%;margin-left: 35%">
    <div style="margin-top: 30px;margin-left: 20%;width: 60%">
        <form class="layui-form layui-form-pane" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">账号：</label>
                <div class="layui-input-block">
                    <input type="text" name="username" required lay-verify="required" placeholder="请输入用户名"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码：</label>
                <div class="layui-input-block">
                    <input type="text" name="password" required lay-verify="required" placeholder="请输入用户名"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">验证码：</label>
                <div class="layui-input-block">
                    <input type="text" style="width: 200px" name="yzm" required lay-verify="required"
                           placeholder="请输入用户名"
                           autocomplete="off" class="layui-input"><img src="/api/user/createcode.do" id="imgs"
                                                                       @onclick="changeImg">
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">登录</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    var $
    layui.use(['form', 'laydate', 'upload'], function () {
        var upload = layui.upload;
        var form = layui.form,
            laydate = layui.laydate,
            $ = layui.$;


        form.on('submit(formDemo)', function (data) {
            console.log(data.field)
            //请求新增接口 Ajax post
            $.get("/api/user/is.do", data.field, function (res) {
                console.log(res)
                //验证接口的返回 是否成功
                if (res.code == 0) {
                    location.href = "/index.html"
                } else {
                    layer.msg("登录失败");
                }
            });
            return false;
        });
        $.get("/api/user/selectAll.do", function (res) {
            //验证接口的返回 是否成功
            if (res.code == 0) {
                console.log(res.data)
                var data = res.data
                for (a in data) {
                    $("#sele").append("<option value='" + data[a].id + "'>" + data[a].username + "</option>")
                }
                layui.form.render("select");
            } else {
                layer.msg(res.data);
            }
        })
    });

</script>
</body>


</html>